* T1 Baseline Summary Statistics and Balance : Sample used to study investments and agricultural outcomes
* Last Updated, Niriksha Shetty 03/31/206

clear
clear mata
clear matrix
set maxvar 20000
set more off

pwd
cap cd c(`pwd')

estimates clear

use "../dta/reduced-form-master.dta", clear

*Using balanced panel
keep if bal_panel3==1

* Summary Statistics
local vars "kval_w1_real cost_k_w1_real b110rk_w1_real b111rk_w1_real b112pk_w1_real total_mandays_k_w1 total_hired_mandays_k_w1 total_fam_mandays_k_w1 profit_k_w1_real fraction_hy_k fraction_cashcrop_k plotsize_ha totalrevenues_w1_real totalcosts_w1_real totalprofit_w1_real"
qui estpost summarize `vars' if mkt_year==2005
est sto A 
qui estpost summarize `vars' if Tvillage==0 & mkt_year==2005 
est sto B
qui estpost summarize `vars' if originaltvillage==1 & mkt_year==2005 
est sto C 
qui estpost summarize `vars' if firstt_2007==1 & mkt_year==2005 
est sto D
esttab A B C D  using "../output/sum-t1.csv", cells("mean(fmt(2))" replace sd(par fmt(2))) nolabel noabbrev title("Summary statistics") collabels("Mean") mtitle("Full" "Control" "T1" "T2" ) nonum replace 

* Balance Tests
tempvar tmp
gen `tmp' = .
foreach var of local vars {
reg `var' originaltvillage firstt_2007 if mkt_year == 2005, cluster(villageno)
replace `tmp' = Ftail(e(df_m),e(df_r),e(F))
label var `tmp' `var'
estpost summarize `tmp' if mkt_year == 2005
est sto A
esttab A using "../output/bal-t1.csv", cells("mean(fmt(2))") label noabbrev collabels("p-value") mtitle("") noobs nonum append
replace `tmp' = .
estimates clear
}

